Mysql Commands

Mysql commands for Ubuntu

 

1. To install Mysql on ubuntu   

sudo apt-get install mysql-server  

 

2. To access or login to MySql the below command need to run from terminal. 

mysql -u root -p 

and it asks for the database password and we need to enter the password .  Where "root" is user-name of database   Two points to keep in mind:  Every  MySql commands must  end with a semicolon; if the command does not  end with a semicolon, the command will not execute and it prompt to next line without execution. 

 

3. To see all databases  

SHOW DATABASES;

e.g :  mysql> SHOW DATABASES;

 

4. To create a new database in MySql

 CREATE DATABASE database name;

e.g : mysql> CREATE DATABASE letsknowit;

You can check the database is created or not by running SHOW DATABASES; command and the new

database created will show in the listing .

 

5. To delete a database

DROP DATABASE database name;

 

6. To Access a  Database

   To open/access a database we can use  

mysql>USE databse_name;

 e.g. mysql> letsknowit;

 

7. To view the tables present in an existing database

 mysql>SHOW TABLES;

This will list all tables available in the present database, however if the database have no tables then a message will prompt "Empty set".

 

8. Create A MySql Table

   Let's create a table of student that contains StudentId, Studentname and StudentShoolname. 

CREATE TABLE student (StudentId INT NOT NULL PRIMARY KEY AUTO_INCREMENT,  Studentname VARCHAR(20), StudentShoolname VARCHAR(30);

To view the table use SHOW TABLES; command

mysql>SHOW TABLES;

 

9. To see the table complete structure we use

 mysql>DESCRIBE student;

 

10. Add a column to existing Table

 ALTER  TABLE [TABLE NAME] ADD [COLUMN NAME] AFTER [COLUMN NAME];

e.g. Mysql> ALTER  TABLE  student ADD  email VARCHAR(55) AFTER Studentname;

 

11. Delete a column from existing table

ALTER  TABLE [TABLE NAME] DROP [COLUMN NAME];

Mysql> ALETR TABLE student DROP email;

 

12. Add  values to an existing table

To add values to the existing table ‘student’ we will use below format

INSERT INTO  [TABLE NAME] ([COLUMN NAME1], [COLUMN NAME2], [COLUMN NAME3] ) VALUES ([VALUE1], [VALUE2], [VALUE3]);

INSERT INTO `student` (`StudentId`,`Studentname`,`StudentSchoolname`) VALUES (NULL, "Jack", "RLB School");

INSERT INTO `student` (`StudentId`,`Studentname`,`StudentSchoolname`) VALUES (NULL, "Tom", "RLB School");

To check the above values in our table student

Mysql>SELECT * FROM student;

 13. Update values of table

 UPDATE  [TABLE NAME] SET [COLUMN NAME]= [NEW VALUE] WHERE [COLUMN NAME]= [FIELD VALUE]

e.g. Mysql> UPDATE student SET Studentname=’tim’ WHERE student.StudentId = 1;

 14. Delete row from a table

DELETE FROM [TABLE NAME] WHERE [COLUMN NAME]= [FIELD VALUE]

Mysql >DELETE FROM Student WHERE StudentId = 1;

15. Assign User to Database

GRANT ALL PRIVILEGES ON database_name.* TO 'database_user'@'host_name';

0   0
Aditya Singh
profile feheye 22nd November 2024

A well-installed raised floor panel ensures smooth cable management and easy access to the infrastructure that powers your workspace. raised floor panel

Write a comment ...
Post comment
Cancel
profile feheye 22nd November 2024

If you're looking for a place to enjoy some exciting games and great service, Hilton Casino is the spot. Always a great time! 클락 힐튼 호텔

Write a comment ...
Post comment
Cancel
profile feheye 21st November 2024

Before borrowing money, calculate how the additional debt will affect your overall financial situation. 急需借錢

Write a comment ...
Post comment
Cancel
profile feheye 21st November 2024

Borrowing money from family is tricky, but sometimes necessary. I try to approach it with transparency and a clear timeline for repayment. Does anyone else find this helps. 借錢網站

Write a comment ...
Post comment
Cancel
profile hunain 20th November 2024

This kind of is a wonderful submit My partner and i noticed as a result of discuss that. It is just what I desired to find out desire inside upcoming you may keep on regarding revealing this kind of outstanding submit. iptv uk

Write a comment ...
Post comment
Cancel
profile hunain 20th November 2024

This kind of is a wonderful submit My partner and i noticed as a result of discuss that. It is just what I desired to find out desire inside upcoming you may keep on regarding revealing this kind of outstanding submit. iptv uk

Write a comment ...
Post comment
Cancel
profile jack 19th November 2024

This kind of is a wonderful submit My partner and i noticed as a result of discuss that. It is just what I desired to find out desire inside upcoming you may keep on regarding revealing this kind of outstanding submit. Best iptv

Write a comment ...
Post comment
Cancel
profile Diana 27th September 2024

Perfect! Thanks mate..


Diana- CEO- hills district solar installers

Write a comment ...
Post comment
Cancel
profile ZenGlow 20th September 2024

Achieve your desired shape with our innovative body contour solutions today.

Write a comment ...
Post comment
Cancel
profile inserts 13th September 2024

Your Drilling tool inserts insights are special Inserts always cutting tool precision inserts so VBMT Insert valuable.I really really Tungsten Carbide Inserts love Turning Inserts high feed milling Insert parting tool Inserts lathe machine cutting tools it.

Write a comment ...
Post comment
Cancel
profile Uniswift.pk 1st September 2024

Welcome to Uniswift, your go-to destination for basketball Pakistan. From premium basketballs to hoops and accessories, we've got everything you need to shoot hoops like a pro. Elevate your game with Uniswift's top-quality basketball equipment and dominate the court!

Write a comment ...
Post comment
Cancel
profile Shalamar Hospital 31st August 2024

Shalamar Hospital's  dental clinic in Lahore  is committed to providing top-notch dental services, combining expertise with a patient-focused approach for your complete satisfaction.

Write a comment ...
Post comment
Cancel
profile Cara 27th June 2024

Good tips.. Remember to always back up your data before making significant changes with MySQL commands.


Cara at sydney audio visual consultant

Write a comment ...
Post comment
Cancel
profile Shalamar Hospital 24th June 2024

Experience Shalamar Hospital's state-of-the-art prosthetic services. We provide individualized solutions to improve quality of life and restore mobility using cutting edge technology and knowledgeable specialists. Put your trust in Shalamar Hospital for thorough prosthetic care so you can confidently restore your independence.

Write a comment ...
Post comment
Cancel
profile Uniswift 24th June 2024

Uniswift.ae celebrates the spirit of the dubai football team Dive into our exclusive collection of team merchandise and show your support with pride. Explore Uniswift.ae today for all your Dubai football team gear needs.

Write a comment ...
Post comment
Cancel

Related Post

Please rotate your device

We don't support landscape mode on your device. Please rotate to portrait mode for the best view of our site